from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager

Builder.load_file('goblinoid/root/goblinscreenmanager.kv')


class GoblinScreenManager(ScreenManager):

    def __init__(self, **kwargs):
        self.register_event_type('on_comment')
        self.register_event_type('on_feed_refreshing')
        self.register_event_type('on_feed_refreshed')
        self.register_event_type('on_pull_to_refresh')
        self.register_event_type('on_no_service')
        super(GoblinScreenManager, self).__init__(**kwargs)

    def on_comment(self, *largs):
        print (self.current_screen.name)
        self.current_screen.dispatch('on_comment', *largs)
        return True
        # eventually going to use the code below when every screen is a goblinscreen
        # for screen in self.screens:
        #     print ('dispatching to each screen')
        #     screen.dispatch('on_comment', *largs)

    def on_feed_refreshing(self, *args):
        self.current_screen.dispatch('on_feed_refreshing', *args)
        return True

    def on_feed_refreshed(self, *args):
        self.current_screen.dispatch('on_feed_refreshed', *args)
        return True

    def on_pull_to_refresh(self, *args):
        self.current_screen.dispatch('on_pull_to_refresh', *args)
        return True

    def on_no_service(self, *args):
        self.current_screen.dispatch('on_no_service', *args)
        return True
